<template>
  <div id="index" class="homePage">
    <div id="bignav">
      <IndexHeader :lang="lang" :marketA="marketAn"></IndexHeader>
    </div>
    <!-- 市场 -->
    <IndexMarket :lang="lang" :marketAnList="marketAnList"></IndexMarket>
    <!-- 新闻 -->
    <div class="news" v-if="customInfo.News || customInfo.Business">
      <div class="body">
        <div class="news-title">
          <h2 :class="{active: parseInt(newType) === 1}" @click="getArticleList(1)" v-if="customInfo.News">{{lang['news']}}</h2>
          <span class="v-line" v-if="customInfo.News && customInfo.Business"></span>
          <h2 :class="{active: parseInt(newType) === 3}" @click="getArticleList(3)" v-if="customInfo.Business">{{lang['enterpriseNews']}}</h2>
        </div>
        <div class="news_list">
          <ul>
            <li v-for="item in newslist">
              <a @click='news_details(item.Keywords)'>
                <div class="tupian">
                  <img :src="item.Icon">
                  <div class="data">
                    <p>{{lang[formatDate2(item.CreateTime, 'MM')]}}</p>
                    <em>{{formatDate3(item.CreateTime, 'dd')}}</em>
                    <p>{{formatDate(item.CreateTime, 'yyyy')}}</p>
                  </div>
                </div>
                <h3 class="title">{{item.Title}}</h3>
                <p class="words">{{item.Introduce}}</p>
              </a>
            </li>
          </ul>
        </div>
        <div class="loadMore">
          <a href="#" @click="linkToNews">{{lang['indexMore']}}</a>
        </div>
      </div>
    </div>
    <!-- 核心优势 -->
    <div class="advantage" v-if="customInfo.Advantage">
      <div class="body">
        <h3>{{lang['core advantages']}}</h3>
        <ul>
          <li>
            <img src="./images/advan-icon-01.png" alt="">
            <h4>{{lang['High liquidity']}}</h4>
            <div class="cover">
              <p>{{lang['IDC Alliance Shares Liquidity']}}</p>
            </div>
          </li>
          <li>
            <img src="./images/advan-icon-02.png" alt="">
            <h4>{{lang['safe and stable']}}</h4>
            <div class="cover">
              <p>{{lang['2 million transactions per second, cold wallet save']}}</p>
            </div>
          </li>
          <li>
            <img src="./images/advan-icon-03.png" alt="">
            <h4>{{lang['Legal currency']}}</h4>
            <div class="cover">
              <p>{{lang['US dollar and Hong Kong dollar recharge extraction']}}</p>
            </div>
          </li>
          <li>
            <img src="./images/advan-icon-04.png" alt="">
            <h4>{{lang['Leverage algorithm']}}</h4>
            <div class="cover">
              <p>{{lang['3x leverage and advanced algorithmic trading strategies']}}</p>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <!-- download -->
    <div class="iMbanner"  v-if="customInfo.Download">
      <div class="iMbannerMain">
        <div class="left">
          <h3>IDCM App</h3>
          <font>{{lang['indexBrowseTheMarket']}}、{{lang['indexFingertipsGrasp']}}、{{lang['indexHeartyDealr']}}</font>
          <img id="bateLogo" v-show="false" src="./images/logo-beta.png" /> <!-- logo占位 -->
          <img id="normalLogo" v-show="false" src="./images/logo-normal.png" /> <!-- logo占位 -->
          <div class="img-list">
            <div class="left block-bg">
              <p>iOS (Beta)、 Android</p>
              <span class="code" id="bate"></span>
            </div>
            <div class="right">
              <div class="apple">
                <span class="btn"></span>
                <div class="block-bg">
                  <p>App Store</p>
                  <span class="code" id="appStore"></span>
                </div>
                <router-link class="link" to="/help/tutorial" v-show="langKey === 'zh-CN'">非国际用户下载教程</router-link>
              </div>
              <div class="google">
                <span class="btn"></span>
                <div class="block-bg">
                  <p>Google Play</p>
                  <span class="code" id="android"></span>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="right">
          <img src="./images/phone.png">
        </div>
      </div>
    </div>
    <!-- IDCG -->
    <div class="alliance" v-if="customInfo.Member || customInfo.Partner">
      <div class="idcg" v-if="customInfo.Member">
        <div class="header">
          <a href="http://www.idcg.io" target="_blank">
            <img src="./images/IDCG.png" />
            <img src="./images/IDCG-hover.png" />
          </a>
        </div>
        <ul class="list">
          <router-link to="/help/about" class="link">
            <img src="./images/IDCA.png" />
            <img src="./images/IDCA-hover.png" />
          </router-link>
          <router-link to="/help/about" class="link">
            <img src="./images/IDCM.png" />
            <img src="./images/IDCM-hover.png" />
          </router-link>
          <a href="#" class="link">
            <img src="./images/DTX.png" />
            <img src="./images/DTX-hover.png" />
          </a>
          <a href="https://www.idcw.io" class="link">
            <img src="./images/IDCW.png" />
            <img src="./images/IDCW-hover.png" />
          </a>
          <a href="http://www.idcam.io/" class="link">
            <img src="./images/IDCAM.png" />
            <img src="./images/IDCAM-hover.png" />
          </a>
          <a href="http://www.idcr.io/" class="link">
            <img src="./images/IDCR.png" />
            <img src="./images/IDCR-hover.png" />
          </a>
        </ul>
      </div>
      <div class="partner" v-if="customInfo.Partner">
        <h3 v-text="lang && lang['Partner']"></h3>
        <ul class="list">
          <li class="item">
            <a href="http://www.amberaigroup.com" target="_blank">
              <img src="./images/AMBER.png">
              <img src="./images/AMBER01.png">
            </a>
          </li>
          <li class="item">
            <a href="https://www.orichal.io" target="_blank">
              <img src="./images/ORICHAL.png">
              <img src="./images/ORICHAL01.png">
            </a>
          </li>
          <li class="item">
            <a href="http://www.mavensecurities.com" target="_blank">
              <img src="./images/MAVEN.png">
              <img src="./images/MAVEN01.png">
            </a>
          </li>
          <li class="item">
            <a href="https://www.reuters.com" target="_blank">
              <img src="./images/REUTERS.png">
              <img src="./images/REUTERS01.png">
            </a>
          </li>
          <li class="item">
            <a href="http://vhkd.io" target="_blank">
              <img src="./images/PVHKD.png">
              <img src="./images/PVHKD01.png">
            </a>
          </li>
          <li class="item">
            <a href="https://www.bloomberg.com" target="_blank">
              <img src="./images/BLOOMBERG.png">
              <img src="./images/BLOOMBERG01.png">
            </a>
          </li>
          <li class="item">
            <a href="https://bitcoinfoundation.org" target="_blank">
              <img src="./images/THE.png">
              <img src="./images/THE01.png">
            </a>
          </li>
          <li class="item">
            <a href="https://icspa.org" target="_blank">
              <img src="./images/ICSPA.png">
              <img src="./images/ICSPA01.png">
            </a>
          </li>
        </ul>
      </div>
    </div>
    <!-- 页脚 -->
    <PageFooter2 :lang="lang" :langKey="langKey"></PageFooter2>
  </div>
</template>

<script>
import commonMixins from '@/mixins/common.js'
import IndexNews from '../news/index.vue'
import Utils from '@/utils/Utils.js'
import IndexHeader from './components/Head.vue'
import IndexMarket from './components/market.vue'
import {mapGetters} from 'vuex'

export default {
  mixins: [commonMixins],
  data () {
    return {
      h5: 'https://m.idcm.io/download',
      iOSUrl: '',
      androidUrl: '',
      downloadList: [],
      newslist: '',
      isPlaying: true,
      langKeyType: '',
      marketAn: [],
      marketAnList: {},
      newType: 1  // 新闻类型
    }
  },
  computed: {
    ...mapGetters({
      customInfo: 'customInfo' // 获取站点个性化配置信息
    }),
    // 根据后台设置是否显示相关新闻类型，动态设置默认请求新闻类型
    defaultNewType: function () {
        return this.customInfo.News ? 1 : 3
    }
  },
  components: {
    IndexNews,
    IndexHeader,
    IndexMarket
  },
  watch: {
    langKey () {
      this.getArticleList(this.newType)
      this.getAnList()
      // this.updateQRCode()
    }
  },
  methods: {
    // 跳转到新闻页
    linkToNews () {
      this.$router.push({path: '/news/index'})
    },
    getAnList () {
      // 公告列表列表读取
      this.$http.post('Article/GetLatestAnnouncement', {
        top: 5
      }, {
        isQueryString: true
      })
      .then((res) => {
        if (res.StatusCode === '200') {
          this.marketAn = res.Data || []
          this.marketAnList = this.marketAn[0] || {}
        }
      })
    },
    formatDate (date) {
      return Utils.formatDate(new Date(date), 'yyyy')
    },
    formatDate2 (date) {
      return Utils.formatDate(new Date(date), 'MM')
    },
    formatDate3 (date) {
      return Utils.formatDate(new Date(date), 'dd')
    },
    news_details (keywords) {
      this.$router.push({
        path: '/news/detail',
        query: {
          keywords: keywords
        }
      })
    },

    // 获取新闻列表
    getArticleList (type) {
      this.newType = type
      this.$http.post('Article/GetArticleList', {
        pageIndex: 1,
        pageSize: 3,
        articleType: this.newType
      })
      .then((res) => {
        if (res.StatusCode === '200') {
          this.newslist = res.Data || []
          Utils.fixNewDateStringWithArrayForIE(this.newslist, 'CreateTime')
          this.total = res.TotalItem
        }
      })
    },

    // 获取APP下载链接
    getCode () {
      let self = this
      this.$http.post('Version/All', {})
      .then((res) => {
        if (res) {
          self.downloadList = res || []
          self.downloadUrl(self.downloadList)
        }
      })
    },

    // 分别获取安卓和iOS
    downloadUrl (data) {
      let self = this
      for (var i = 0; i < data.length; i++) {
        let url = data[i].QRContent
        if (data[i].client_type === 1) {
          if (self.androidUrl === '') {
            self.androidUrl = data[i].QRContent
          }
        } else if (data[i].client_type === 2 && data[i].app_market === 'AppStore') {
          if (self.iOSUrl === '') {
            self.iOSUrl = data[i].QRContent
          }
        }
      }
      this.transParameter()
    },

    // 前端生成二维码和(节点，地址，中间图标)
    createQRCode (id, url, bate) {
      setTimeout (() => {
        $('#' + id).find('canvas').remove()
        $('#' + id).qrcode({
          render: 'canvas',
          quiet: 2,
          size: 140,
          fill: '#000',
          background: '#fff',
          ecLevel: 'H',
          minVersion: 1,
          maxVersion: 40,
          text: url,
          mode: 4,
          image: $('#' + bate)[0],
          mSize: parseInt(12, 12) * 0.02
        })
      }, 0)
    },

    // 传参到二维码插件
    transParameter () {
      let self = this
      self.createQRCode('bate', 'https://m.idcm.io/download', 'bateLogo')  // 内侧版
      self.createQRCode('android', self.androidUrl, 'normalLogo')  // 谷歌安卓
      self.createQRCode('appStore', self.iOSUrl, 'normalLogo')  // iOS
    }
  },
  mounted () {
    window.onscroll = function () {
      var topScroll = document.documentElement.scrollTop // 滚动的距离,距离顶部的距离
      var bignav = document.getElementById('bignav') // 获取到导航栏id
      if (!bignav) return
      if (topScroll > 100) {
      // 当滚动距离大于250px时执行下面的东西
        bignav.classList.add('mystyle')
      } else { // 当滚动距离小于250的时候执行下面的内容，也就是让导航栏恢复原状
        bignav.classList.remove('mystyle')
      }
    }
    this.getArticleList(this.defaultNewType)
    this.getAnList()
    this.getCode()
    }
}
</script>

<style lang="less">

.active-background {
  position: fixed;
  z-index: 100;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.8);
  top: 0;
  bottom: 0;

  .active-main {
    position: relative;
    width: 1000px;
    margin: 10% auto 0;
  }


  .active-close {
    position: absolute;
    top: 0;
    right: 0;
  }
  .active-subimt {
    display: block;
    margin: 0 auto;
    cursor: pointer;
  }
}
.homePage {
  #bignav {
    position: absolute;
    top: 0;
    z-index: 100;
    width: 100%;
    transition: 1s;
   }

  #bignav.mystyle {
    position: fixed;
    top: 0;
    z-index: 999;
    background: #14141c;

    .indexHead .pageAnnouncement{
      background-color: rgba(0,0,0,0);
    }
  }

  .news {
    width: 100%;
    min-width: 800px;
    background-color: #101e36;

    .body {
      margin: 0 auto;
      width: 1200px;

      .news-title {
        text-align: center;
        position: relative;
        margin-bottom: 30px;

        h2 {
          font-size: 24px;
          text-align: center;
          color: #fff;
          margin: 0 25px;
          display: inline-block;
          cursor: pointer;
          position: relative;
        }
        h2.active {
          position: relative;
          color: #3782FF;

          &:before{
            display: block;
            content:'';
            position: absolute;
            left: 30%;
            bottom: -10px;
            width: 40%;
            border-bottom: solid 1px #3782FF;
          }
        }
        .v-line {
            position: relative;
            top: 5px;
            display: inline-block;
            content:'';
            height: 28px;
            width: 1px;
            background-color: #fff;
        }
      }
      .loadMore {
        clear: both;
        overflow: hidden;
        a {
          display: block;
          margin: 30px auto;
          width: 425px;
          line-height: 36px;
          height: 36px;
          border-radius: 100px;
          background-color: #3782FF;
          color: #fff;
          text-align: center;
        }
      }

      .news_list {
        clear: both;
        li {
          min-height: 320px;
          width:auto;
          padding: 20px 0;
          margin-right: 45px;
          float: left;

          a {
            display: block;
            width: 370px;

            .tupian {
              min-height: 234px;
              position: relative;

              img {
                display: block;
                max-width: 100%;
                height: auto;
                transition: all .3s;
                border-radius: 4px;
              }

              .data {
                position: absolute;
                top: -14px;
                left: 0;
                padding: 5px 10px;
                box-shadow: 0 2px 6px 0 rgba(0,0,0,0.25);
                border-radius: 4px;
                background-color: white;
                text-align: center;

                p {
                  font-size: 14px;
                  color: #333;
                }

                em {
                  font-size: 16px;
                  text-align: center;
                  color: #3782FF;
                  padding: 8px 0;
                  font-weight: bold;
                  display: inline-block;
                }
              }
            }
          }

          .title {
            font-size: 16px;
            height: 24px;
            line-height: 24px;
            margin: 15px 0;
            font-weight: bold !important;
            color: #eee;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
            /*word-break: break-all;*/
            overflow: hidden;
          }

          .words {
            color: #ccc;
            font-size: 14px;
            line-height: 20px;
            height: 42px;
            box-sizing: border-box;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            /*word-break: break-all;*/
            overflow: hidden;
          }
          &:nth-of-type(3n) {
            margin-right: 0;
          }
        }
      }
    }
  }

  .advantage {
    padding: 40px 0;
    width: 100%;
    min-width: 800px;
    .body {
      width: 1100px;
      margin: 0 auto;

      h3 {
        text-align: center;
        color: white;
        margin: 20px 0 40px;
        font-size: 24px;
      }

      ul {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        li {
          flex: 1;
          margin-right: 20px;
          color: white;
          padding: 10px;
          text-align: center;
          position: relative;
          overflow: hidden;

          .cover {
            left: 0;
            right: 0;
            bottom: 0;
            top: 100%;
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            border-radius: 10px;
            background-color: rgba(15, 48, 88, 0.9);
            position: absolute;
            transition: all 0.5s ease;

            p {
              position: absolute;
              top: 50%;
              left: 50%;
              width: 96%;
              transform: translate(-50%, -50%);
              text-align: center;
              line-height: 24px;
            }
          }

          img {
            width: 100%;
          }

          h4 {
            margin: 20px 0;
            font-size: 18px;
          }
        }

        li:hover {
          .cover {
            top: 0;
            transition: all 0.4s ease;
          }
        }

        li:last-child {
          margin-right: 0;
        }
      }
    }
  }

  .iMbanner {
    position: relative;
    width: 100%;
    min-width: 800px;
    background: #171b2b url('./images/download-background.png') no-repeat center bottom;
    overflow: hidden;
    background-size: cover;

    .iMbannerMain {
      width: 1200px;
      height: 482px;
      overflow: hidden;
      margin: 0 auto;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;

      .left {
        display: flex;
        flex-direction: column;
        color: #fff;

        h3 {
          font-size: 40px;
        }

        font {
          margin: 26px 0;
          font-size: 18px;
        }

        .img-list {
          display: flex;
          flex-direction: row;
          align-items: center;

          .left {
            &.block-bg {
              p {
                padding: 20px 0;
                box-sizing: border-box;
              }
            }
          }

          .right {
            display: flex;
            flex-direction: column;
            text-align: center;
            margin:  0 0 0 34px;
            position: relative;

            .apple {
              display: flex;
              flex-direction: column;

              .btn {
                background-image: url('./images/iOS-btn.png');
                background-size: cover;
                transition: all 0.2s;

                &:hover {
                  background-image: url('./images/iOS-btn-hover.png');
                }
                &:hover+.block-bg {
                  display: block;
                }
              }
              .link {
                width: 130px;
                padding: 8px 10px;
                margin: 6px auto 0 auto;
                box-sizing: border-box;
                border: 1px solid #fff;
                border-radius: 6px;
                display: inline-block;
                font-size: 12px;
                color: #fff;
                transition: all 0.2s;

                &:hover {
                  color: #3782FF;
                  border-color: #3782FF;
                }
              }
            }

            .google {
              margin-top: 20px;

              .btn {
                background-image: url('./images/google-btn.png');
                background-size: cover;
                transition: all 0.2s;

                &:hover {
                  background-image: url('./images/google-btn-hover.png');
                }
                &:hover+.block-bg {
                  display: block;
                }
              }
            }

            .btn {
              width: 180px;
              height: 40px;
              display: inline-block;
              cursor: pointer;
            }

            .block-bg {
              position: absolute;
              top: 50%;
              right: -210px;
              transform: translateY(-50%);
              display: none;

              p {
                padding: 20px 0;
                box-sizing: border-box;
              }
            }
          }

          .block-bg {
            width: 180px;
            height: 214px;
            background-color: #040326;
            border-radius: 10px;
            text-align: center;
          }
        }
      }
      .right {
        margin-top: 20px;
      }
    }
  }

  .alliance {
    background-color: rgba(8, 20, 40, 1);

    .idcg {
      padding: 60px 0;
      .header {
        width: 1200px;
        margin: 0 auto;
        position: relative;
        display: flex;
        flex-direction: row;
        justify-content: center;

        a {
          height: 116px;
          overflow: overflow;

          img:last-child {
            display: none;
          }
          &:hover img:first-child {
            display: none;
          }
          &:hover img:last-child {
            display: block;
          }
          overflow: hidden;
        }

        &::before {
          content: "";
          position: absolute;
          left: 10%;
          width: 30%;
          top: 50%;
          height: 1px;
          transform: translateY(-50%);
          background: linear-gradient(90deg, rgba(117, 161, 255, 0), rgba(117, 161, 255, 0.8));
          transform: rotate(360deg);
        }
        &::after {
          content: "";
          position: absolute;
          right: 10%;
          width: 30%;
          top: 50%;
          height: 1px;
          transform: translateY(-50%);
          background: linear-gradient(90deg, rgba(117, 161, 255, 0.8), rgba(117, 161, 255, 0));
          transform: rotate(0deg);
        }
      }
      .list {
        width: 1200px;
        margin: 80px auto 0;
        display: flex;
        flex-direction: row;
        justify-content: space-between;

        a {
          img:last-child {
            display: none;
          }
          &:hover img:first-child {
            display: none;
          }
          &:hover img:last-child {
            display: block;
          }
        }
      }
    }

    .partner {
      padding: 50px 0;
      background-color: rgba(17, 29, 53, 1);

      h3 {
        font-size: 24px;
        color: white;
        text-align: center;
      }

      .list {
        width: 1200px;
        margin: 20px auto;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        flex-wrap: wrap;

        .item {
          width: 270px;
          height: 140px;
          overflow: hidden;
          margin-top: 20px;
          text-align: center;
          position: relative;
          img {
            margin: 0 auto;
            width: 100%;
          }

          img:last-child {
            display: none;
          }
        }

        .item:hover {
          img:first-child {
            display: none;
          }

          img:last-child {
            display: block;
          }
        }
      }
    }
  }

  .cover {
    width: 100%;
    height: 100%;
    position: fixed;
    z-index: 999;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    text-align: center;

    .content {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      .image {
        position: relative;

        .close {
          position: absolute;
          top: -20px;
          right: 160px;
          cursor: pointer;
        }
      }
      .btn {
        margin: 20px auto;
      }
    }
  }
}

/*== 适配 ==*/
@media only screen and (max-width: 1200px) {
  #index.homePage {
    .section {
      width: 100%;
      min-width: 800px;

      .banner {
        .bannerMain {
          display: none;
        }
        .indexAnnouncement {
          z-index: 10;

          .indexAnnouncementMain {
            width: 760px;
          }
        }
        .swiper-wrapper {
          /* img {
            height: auto;
          } */
        }
      }
    }
    .swiper-container {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
      top: 0;
      .more {
        display: none;
      }
      .swiper-pagination {
        bottom: 60px;
        text-align: center;
      }
    }

    .transaction {
      .body {
        width: 760px;
        .header {
          .row {
            .item {
              padding: 0 10px;
            }
          }
        }
        .content {
          .row {
            .item {
              padding: 0 10px;
              text-indent: 0;
            }
          }
        }
        .idca {
          .alliance-count {
            ul {
              flex-wrap: wrap;

              li {
                width: 41%;
                flex: initial;
                margin: 0;
              }
              li:first-child {
                margin: 0 0 30px 26%;
              }
            }
          }
          .country {
            width: 100%;
          }
        }
      }
      .w10 {
        width: 15%;
      }
    }

    .news {
      .body {
        width: 100%;

        .news_list {
          ul {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            padding: 0 20px;

            li {
              margin: 0;
              width: 47%;
              a {
                width: 100%;
              }
            }
            li:nth-child(3) {
              display: none;
            }
          }
        }
      }
    }

    .advantage {
      width: 100%;
      min-width: 800px;
      .body {
        width: 100%;
        ul {
          flex-wrap: wrap;
          justify-content: center;
          li {
            width: 34%;
            overflow: hidden;
            box-sizing: border-box;
            flex: inherit;
            margin: 0;
          }
        }
      }
    }

    .iMbanner {
      width: 100%;
      min-width: auto;
      text-align: center;

      .iMbannerMain {
        width: 100%;
        .left {
          width: 100%;
          min-width: 800px;
          .img-list {
            justify-content: center;
            padding: 0 40px;
            box-sizing: border-box;
            .item {
              margin: 0 40px;
            }
          }
        }
        .right {
          display: none;
        }
      }
    }

    .alliance {
      min-width: 800px;
      .idcg {
        .header {
          width: 100%;
        }
        .list {
          padding: 0 40px;
          width: 100%;
          margin-top: 30px;
          flex-wrap: wrap;
          box-sizing: border-box;
          justify-content: center;
          .link {
            margin: 0 30px 20px 30px;
          }
        }
      }
    }

    .partner {
      .list {
        width: 100%;
        padding: 0 40px;
        box-sizing: border-box;
        justify-content: center;

        .item {
          margin: 20px;
        }
      }
    }
  }
}
</style>
